﻿<UserControl x:Class="ShumaDaf.DataTabControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:my="clr-namespace:ShumaDaf"
             xmlns:Convert="clr-namespace:Sherbanov.Converters"
             mc:Ignorable="d"  Width="{Binding ElementName=Parent, Path=Width}">
    <UserControl.Resources>
        <XmlDataProvider x:Key="myXmlDataTable" XPath="/Collection/CollectionRecord" />
        <my:RuntimeConverter x:Key="runtime" />
        <my:Int2ColorConverter x:Key="colorConv" />
        <my:StatusColorConv x:Key="StatusColorConv" />
        <Convert:b2gbConverter x:Key="b2g" />
        <my:Int2CheckConverter x:Key="int2check" />
        <my:s2i x:Key="s2i"></my:s2i>

        <my:DesireConverter x:Key="dcon"/>

      

        <Style x:Key="myCheckStyle" TargetType="DataGridCell">
            <!--Setter Property="VerticalAlignment" Value="Center" /-->
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
        </Style>
        <Style x:Key="myDataGridRowStyle" TargetType="DataGridRow" >

        </Style>

    </UserControl.Resources>

    <DockPanel DataContext="{StaticResource myXmlDataTable}">
    
        <DataGrid   DockPanel.Dock="Top"   AutoGenerateColumns="False" ItemsSource="{Binding}" Name="dg1" 
                  RowDetailsVisibilityMode="VisibleWhenSelected" CanUserAddRows="False" Sorting="dg1_Sorting" RowEditEnding="dg1_RowEditEnding" Loaded="dg1_Loaded">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <EventSetter Event="MouseRightButtonUp" Handler="eventDataGridRowMouseRightButtonUp" />
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.Columns>
                <!--DataGridTextColumn    xml:space="default" x:Name="guidCol" Binding="{Binding XPath=@Shuid}" Header="Shuid" Width="40" IsReadOnly="True"/-->
                <DataGridTextColumn   Binding="{Binding XPath=ScanDateTime}" Header="Scan" Width="Auto" IsReadOnly="True"/>
                <DataGridTextColumn Binding="{Binding XPath=ProductionYear}" Header="Year" Width="SizeToHeader" IsReadOnly="True"></DataGridTextColumn>

                <!--<DataGridTextColumn   Binding="{Binding XPath=DiskStatus}" Header="On/Off-line" Width="Auto" IsReadOnly="True">
                        </DataGridTextColumn>-->


                <DataGridTextColumn  Binding="{Binding XPath=Path}" Header="Path" Width="Auto" IsReadOnly="True">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="{Binding XPath=DiskStatus, Converter={StaticResource StatusColorConv} }" />
                            <EventSetter Event="DataGridRow.MouseDoubleClick" Handler="dataGridRow_MouseDoubleClick"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn  Binding="{Binding XPath=Size, Converter={StaticResource b2g}}" Header="Size" Width="100" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=LocalTitle}" Header="Local Title" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=Country}" Header="Country" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=OriginalTitle}" Header="Original Title" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=CollectionNumber}" Header="Col №" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=Added}" Header="Added(MM)" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=RunningTime, Converter={StaticResource runtime}}" Header="Runtime(MM)" Width="SizeToHeader" IsReadOnly="True"/>
                <DataGridTextColumn  Binding="{Binding XPath=Director}" Header="Director" Width="Auto" MaxWidth="300" IsReadOnly="True"/>

                <DataGridTemplateColumn Header="MediaInfo"  SortMemberPath="MediaInfo/VideoDetails/@FileType">
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="{Binding XPath=DiskStatus, Converter={StaticResource StatusColorConv} }" />
                            <EventSetter Event="DataGridRow.MouseDoubleClick" Handler="MediaInfo_MouseDoubleClick"/>
                        </Style>
                    </DataGridTemplateColumn.CellStyle>

                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock><TextBlock.Text>
                                        <MultiBinding StringFormat=" {2} {0}x{1}">
                                            <Binding XPath="MediaInfo/VideoDetails/@Width"></Binding>
                                            <Binding XPath="MediaInfo/VideoDetails/@Height"></Binding>
                                            <Binding XPath="MediaInfo/VideoDetails/@FileType"></Binding>
                                        </MultiBinding>
                                            <!--<Label.ContentStringFormat>
                                        Actor #1 is {0}
                                    </Label.ContentStringFormat>-->
                                </TextBlock.Text></TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <WrapPanel>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@FileType}">
                                    <Label.ContentStringFormat>FileType: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Format}">
                                    <Label.ContentStringFormat>Format: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@FPS}">
                                    <Label.ContentStringFormat>FPS: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Codec}">
                                    <Label.ContentStringFormat>Codec: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@ScanType}">
                                    <Label.ContentStringFormat>ScanType: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@AspectRatio}">
                                    <Label.ContentStringFormat>AspectRatio: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Width}">
                                    <Label.ContentStringFormat>Width: {0}</Label.ContentStringFormat>
                                </Label>
                                <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Height}">
                                    <Label.ContentStringFormat>Height: {0}</Label.ContentStringFormat>
                                </Label>
                            </WrapPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>

                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Artists"  SortMemberPath="Artists/Person/Name">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock>        <TextBlock.Text>
                                        <MultiBinding StringFormat=" {0}, {1}">
                                            <Binding XPath="Artists/Person[1]/Name"></Binding>
                                            <Binding XPath="Artists/Person[2]/Name"></Binding>
                                        </MultiBinding>
                                            <!--<Label.ContentStringFormat>
                                        Actor #1 is {0}
                                    </Label.ContentStringFormat>-->
                                </TextBlock.Text></TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <ListBox Height="80" ItemsSource="{Binding XPath=Artists/Person/Name, UpdateSourceTrigger=PropertyChanged}" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>

                </DataGridTemplateColumn>

                <DataGridTextColumn  Binding="{Binding XPath=Ratings/Hrez, Converter={StaticResource s2i}}" 
                                    Header="Horiz.Rezol" Width="Auto" SortMemberPath="Ratings/Hrez"/>
                <DataGridTemplateColumn Header="User Rate" Width="Auto" SortMemberPath="Ratings/UserRate">
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="{Binding XPath=Ratings/UserRate, Converter={StaticResource dcon} }" />
                        </Style>
                    </DataGridTemplateColumn.CellStyle>

                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Label Content="{Binding Path=Value,ElementName=sl0}"/>
                                <Slider Name="sl0" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/UserRate}" 
                                        SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding XPath=Ratings/UserRate}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn  Header="Sound Rate" Width="Auto" SortMemberPath="Ratings/SoundRate">
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="{Binding XPath=Ratings/SoundRate, Converter={StaticResource dcon} }" />
                        </Style>
                    </DataGridTemplateColumn.CellStyle>

                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Label Content="{Binding Path=Value,ElementName=sl1}"/>
                                <Slider Name="sl1" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/SoundRate}" SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding XPath=Ratings/SoundRate}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn  Header="Picture Rate" Width="SizeToHeader" SortMemberPath="Ratings/PicRate">
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="{Binding XPath=Ratings/PicRate, Converter={StaticResource dcon} }" />
                        </Style>
                    </DataGridTemplateColumn.CellStyle>

                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Label Content="{Binding Path=Value,ElementName=sl2}"/>
                                <Slider Name="sl2" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/PicRate}" SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate >
                            <Label Content="{Binding XPath=Ratings/PicRate}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn  SortMemberPath="Ratings/OrigSound" Header="Snd" CellStyle="{StaticResource myCheckStyle}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox 
                                        IsChecked="{Binding XPath=Ratings/OrigSound, 
                                        Converter={StaticResource int2check},UpdateSourceTrigger=LostFocus,NotifyOnTargetUpdated=True}" 
                                              IsThreeState="True"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


                <DataGridTemplateColumn SortMemberPath="Ratings/OrigSub" Header="Sub" CellStyle="{StaticResource myCheckStyle}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox 
                                        IsChecked="{Binding XPath=Ratings/OrigSub, 
                                        Converter={StaticResource int2check},UpdateSourceTrigger=LostFocus,NotifyOnTargetUpdated=True}" 
                                              IsThreeState="True" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


                <DataGridTextColumn Binding="{Binding XPath=OperationComment}" Header="Operation comment"/>
            </DataGrid.Columns>
        </DataGrid>

    </DockPanel>
</UserControl>
